<?php

namespace Loop;

/**
 * CXmlFactory
 *
 * @package Loop
 * @category factory
 */

class CXmlFactory
{
    /**
     * Convert a array to an xml
     * 
     * @param array $array Array to convert
     * @param string $rootEntitie XML root entities
     * @param object $xml link to SimpleXMLElement object
     *
     * @return string Array converted to a xml string
     */

     function getXml($array, $rootEntitie) 
    {

        $xml = "<".$rootEntitie.">";
        
        foreach ($array as $key => $value) {
            if(is_numeric($value) === true)
            {
                $xml .= "<{$key}>".$value."</{$key}>";
            }
            else
            {
                $xml .= "<{$key}><![CDATA[".$value."]]></{$key}>";
            }
        } 
        
        $xml .= "</".$rootEntitie.">";
        
        return $xml;
    }
}

?>